package com.example.yiwei.crm.view.activity.areActivity;

import android.content.Intent;
import android.os.Bundle;
import android.support.v7.app.AppCompatActivity;
import android.view.View;
import android.widget.AdapterView;
import android.widget.ImageView;
import android.widget.ListView;

import com.example.yiwei.crm.R;
import com.example.yiwei.crm.base.baseClass;
import com.example.yiwei.crm.dao.areaDao;
import com.example.yiwei.crm.dao_impl.areaDaoImpl;
import com.example.yiwei.crm.entity.AreaEntity;
import com.example.yiwei.crm.view.Class.listviewClass.AreAdapter;

import java.util.List;


public class ProvinceActivity extends AppCompatActivity {
    ImageView imageView;
    private ListView listView;
    List<AreaEntity> areaEntityList;
    AreAdapter areAdapter;
    public static ProvinceActivity a;
    @Override
    protected void onCreate(Bundle savedInstanceState) {
        super.onCreate(savedInstanceState);
        setContentView(R.layout.activity_province);

        a=this;
        imageView= (ImageView) findViewById(R.id.user_add_img_backb);
        imageView.setOnClickListener(new View.OnClickListener() {
            @Override
            public void onClick(View v) {
                finish();
            }
        });
        listView = (ListView) findViewById(R.id.area_lv);
        new Thread(new Runnable() {
            @Override
            public void run() {
                areaDao dao = new areaDaoImpl();
                areaEntityList = dao.queryAreaMessage(baseClass.find_province_url,null);
                runOnUiThread(new Runnable() {
                    @Override
                    public void run() {
                        if (areaEntityList!=null){
                            areAdapter = new AreAdapter(ProvinceActivity.this,areaEntityList);
                            listView.setAdapter(areAdapter);
                        }
                    }
                });
            }
        }).start();
        listView.setOnItemClickListener(new AdapterView.OnItemClickListener() {
            @Override
            public void onItemClick(AdapterView<?> parent, View view, int position, long id) {
                Intent intent = new Intent(ProvinceActivity.this,CityActivity.class);
                intent.putExtra("pid",areaEntityList.get(position).getAreaid());
                intent.putExtra("pname",areaEntityList.get(position).getAreaname());
                startActivity(intent);
            }
        });
    }
}
